//搜索页面控制器
app.controller("search", ["$scope", "$rootScope", "$state", "$http", function($scope, $rootScope, $state, $http) {
	$rootScope.page.showfooter = false;
	scrollTo(0, 0);
	$http({
		method: 'post',
		url: '' + $rootScope.Location + 'Picture/seach_type',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		},
	}).success(function(data) {
		//		console.log(data)
		$scope.data = data
	})
	setTimeout(function() {
		$(".jiantou_click").click(function() {
				$(this).children('.jiantou_top').toggleClass('hidden');
				$(this).children('.jiantou_next').toggleClass('hidden');
				var flag = $(this).hasClass('active');
				if(!flag) {
					$(this).addClass('active');
					$(this).parents(".classification").find(".ol_list").slideDown();
				} else {
					$(this).removeClass('active');
					$(this).parents(".classification").find(".ol_list").slideUp();
				}
			})
			//			$(".Li").click(function() {
			//				$(this).addClass("active");
			//				$(".Li").not(this).removeClass("active")
			//				var Html = $(this).find("span").html()
			//				$(".search").find("input").val(Html)
			//			})
		$(".classification .Li").click(function() {
			if($(this).attr("class") != "Li ng-scope active") {
				$(this).addClass("active").siblings().removeClass("active")
				$(this).addClass("active").parent().siblings().find(".Li").removeClass("active")
			} else {
				$(this).removeClass("active")
			}

		})
	}, 600)
	var str = ""
	$(".toSearch").click(function() {
			if(!$(".search").find("input").val()) {
				for(var i = 0; i < $(".Li").length; i++) {
					var liClass = $(".Li").eq(i).attr("class")
					if(liClass == "Li ng-scope active") {
						str += "," + $(".Li").eq(i).find("span").html()
					}
				}
				$state.go("main.searchlist", {
					name: str
				})

			} else {
				$state.go("main.searchlist", {
						name: "," + $(".search").find("input").val()
					})

			}
		})
		//搜索结果页面
}])
app.controller("searchlist", ["$scope", "$stateParams", "$rootScope", "$state", "$http", function($scope, $stateParams, $rootScope, $state, $http) {
	$rootScope.page.showfooter = true;
	$rootScope.page.footer = 'project';
	scrollTo(0, 0);
	$scope.page.rongcuo = false
	$rootScope.page.goshow = true
	$http({
			method: 'post',
			url: '' + $rootScope.Location + 'House/mixture_seach',
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				name: $stateParams.name
			}
	}).success(function(data) {
		console.log(data)
		$rootScope.page.goshow = false
			if(data["status"] == 1) {
				$scope.House = data["list"]["house"]
				$scope.Road = data["list"]["road"]
				$scope.news = data["list"]["news"]
				if(!data["list"]["news"] && !data["list"]["house"] && !data["list"]["road"]){
					$scope.page.rongcuo = true
				}
			}
			if(data["status"] == 0) {
				$(".addressdialog").show();
				$(".addressdialog").html(data["message"]);
				$(".addressdialog").fadeOut(1200);
			}
		$scope.goprojectInfo = function(id,type){
			if(type==2){
				$state.go("main.newprojectInfo",{
					Id:id
				})
			}else{
				$state.go("main.projectInfo",{
					Id:id
				})
			}			
		}
		$scope.toroutInfo = function(id){
			$state.go("main.routeInfo",{
					Id:id
				})
		}
		$scope.goInfo = function(id){
			$state.go("main.new_info", {
				id: id
			})
		}
	})
}])